import nodemailer from "nodemailer";

async function emailPush(htmlContent) {
  const user = "user email";

  const transporter = nodemailer.createTransport({
    host: "smtp.163.com",
    port: 587,
    secure: true,
    auth: {
      user,
      pass: "your pass",
    },
  });

  const subject = getSubject();

  const info = await transporter.sendMail({
    from: user,
    to: "user email",
    subject,
    html: htmlContent,
  });

  console.log("Message sent: %s", info.messageId);
}

function getSubject() {
  const years = new Date().getFullYear();
  const month = new Date().getMonth() + 1;
  const day = new Date().getDate();

  return `${years}年${month}月${day}天气预报`;
}

export { emailPush };
